package ui.fragment.minefragment;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import adapter.fragment.FragmentPagerItem;
import adapter.fragment.FragmentPagerItemAdapter;
import adapter.fragment.FragmentPagerItems;
import base.fragment.BaseFragment;
import event.OrderEvent;
import student.andlei.com.student.R;

/**
 * author : ChenHuiMing
 * date : 2018/9/17
 * email : 907399255@qq.com
 * description : 我的订单
 */
public class OrderMyFragment extends BaseFragment {

    private ViewPager mViewPager;

    public static Fragment getInstance() {
        return new OrderMyFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_order_my;
    }

    @Override
    protected void findViews() {
        mViewPager = getView(R.id.viewPager);
    }

    @Override
    protected void formatViews() {

    }

    @Override
    protected void formatData() {
        EventBus.getDefault().register(this);
        //左边界面
        FragmentPagerItems pages = new FragmentPagerItems(getContext());
        pages.add(FragmentPagerItem.of("", OrderListFragment.getInstance()));
        pages.add(FragmentPagerItem.of("", OrderPayFragment.getInstance()));
        pages.add(FragmentPagerItem.of("", OrderDetailFragment.getInstance()));
        FragmentPagerItemAdapter rightAdapter = new FragmentPagerItemAdapter(
                getChildFragmentManager(), pages);
        mViewPager.setAdapter(rightAdapter);
        mViewPager.setOffscreenPageLimit(3);
    }

    @Override
    protected void getBundle() {

    }

    @Override
    public void onClick(View view) {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(OrderEvent event) {
        mViewPager.setCurrentItem(event.pagerIndex);
    }
}
